<?php
function fetch_all($res) {
  if ( empty( $res ) ) return array();
  while($row=mysql_fetch_assoc($res)) {
      $return[] = $row;
  }
  return $return;
}
function fetch_one($res,$field=null) {
  if ( empty( $res ) ) return array();	
  while($row=mysql_fetch_assoc($res)) {
      if ( empty($field) ) $return = $row;
      else $return = $row[$field];
  }
  return $return;
}
//数组相关
/**
 * 从数组中取出一列
 */
function get_onecol_in_array( $arr, $k ){
	if ( empty( $arr ) ) return array();
	
	$rt = array();
	foreach ( $arr as $a ){
		$rt[] = $a[$k];
	}

	return $rt;
}
	
function change_key_by_colvalue( $arr, $k ){
	$rt = array();
	
	foreach ( $arr as $v ){
		$rt[$v[$k]][] = $v;	
	}
	
	return $rt;
}